import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from pyqtgraph.parametertree import Parameter, ParameterTree
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout


class MyWidget(QMainWindow):
    def __init__(self):
        super().__init__()

    def load(self):
        # 创建参数树
        params = [
            {'name': 'Group 1', 'type': 'group', 'children': [
                {'name': 'Parameter 1', 'type': 'float', 'value': 0.1},
                {'name': 'Parameter 2', 'type': 'int', 'value': 10}
            ]},
            {'name': 'Group 2', 'type': 'group', 'children': [
                {'name': 'Parameter 3', 'type': 'bool', 'value': False},
                {'name': 'Parameter 4', 'type': 'list',
                    'values': [1, 2, 3], 'value': 2}
            ]}
        ]

        self.param_tree = ParameterTree()
        self.param_tree.setParameters(Parameter.create(
            name='params', type='group', children=params))

        # 添加参数树到布局中
        dock = QDockWidget("属性", self)
        dock.setFloating(False)

        layout = QVBoxLayout()
        layout.addWidget(self.param_tree)
        wid = QWidget()
        wid.setLayout(layout)
        dock.setWidget(wid)
        dock.setAllowedAreas(Qt.DockWidgetArea.RightDockWidgetArea)

        self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, dock)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = MyWidget()
    win.load()
    win.show()
    sys.exit(app.exec_())
